﻿//https://leetcode.cn/problems/daily-temperatures/?envType=study-plan-v2&envId=top-100-liked

class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures)
    {
        int n = temperatures.size();
        vector<int> ans(n, 0);
        stack<int> st;
        for (int i = 0; i < n; i++)
        {
            while (!st.empty() && temperatures[i] > temperatures[st.top()])
            {
                int previndex = st.top();
                ans[previndex] = i - previndex;
                st.pop();
            }
            st.push(i);
        }
        return ans;
    }
};